home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 3.5 KB | 123 lines | [TEXT/ttxt] |
- -- <<<-
-
- -- focevent.sx
- -- Focus Event example
- -- by Howard Metzenberg
- -- Kaleida ScriptX forever
- -- from "Events and Input Devices" chapter of
- -- ScriptX Components Guide
-
- -- This script demonstrates how to manage keyboard focus
- -- on a presenter other than TextEdit
-
- -- Note that this script has changed since ScriptX 1.0
- -- Now you must force focus on a presenter other than TextEdit
-
-
- module EventTest3 uses ScriptX end
- in module EventTest3
-
- class FocusedPresenter (TwoDShape)
- class variables
- focusManager:((new KeyboardDevice).focusManager)
- instance variables
- mouseInterest
- focusInterest
- instance methods
- method init self #rest args -> (
- apply nextMethod self args
- self.focusInterest := new FocusEvent
- self.focusInterest.authorData := self
- self.focusInterest.device := new KeyboardDevice
- self.focusInterest.presenter := self
- self.focusInterest.eventReceiver := processFocus
- addEventInterest self.focusInterest
- self.mouseInterest := new MouseDownEvent
- self.mouseInterest.authorData := self
- self.mouseInterest.presenter := self
- self.mouseInterest.eventReceiver := processMouse
- addEventInterest self.mouseInterest
- )
- -- event receiver for focus events
- method processFocus self interest event -> (
- if (event.focusType = @loseFocus) then (
- -- we lost focus, so show that it is disabled
- event.presenter.fill := whiteBrush
- ) else (
- -- we gained focus, so be colorful!
- local fillcolor := new RGBColor \
- red:(rand 255) green:(rand 255) blue:(rand 255)
- event.presenter.fill := new Brush color:fillcolor
- @accept -- accept the event
- )
- )
- -- event receiver for mouse events
- method processMouse self interest event -> (
- forceFocus FocusedPresenter.focusManager self
- @accept -- accept the event
- )
- end
-
-
- object firstRect (FocusedPresenter)
- boundary:(new rect x2:200 y2:50), fill:whitebrush, stroke:blackbrush
- settings x:50, y:50
- end
- object secondRect (FocusedPresenter)
- boundary:(new rect x2:200 y2:50), fill:whitebrush, stroke:blackbrush
- settings x:50, y:150
- end
- object thirdRect (FocusedPresenter)
- boundary:(new rect x2:50 y2:250), fill:whitebrush, stroke:blackbrush
- settings x:100, y:25
- end
-
- -- now set up a window
- object myWindow (Window)
- boundary:(new Rect x2:400 y2:300), fill:whitebrush
- settings x:16, y:40
- end
- append myWindow firstRect -- add it to the space
- append myWindow secondRect -- add it to the space
- append myWindow thirdRect -- add it to the space
- show myWindow
-
-
- -- example with TextEdit
- module EventTest4 uses ScriptX end
- in module EventTest4
-
-
- object myWindow (Window)
- boundary:(new Rect x2:600 y2:300), fill:whitebrush
- settings x:16, y:40
- end
- object myCursor (Line) x2:0, y2:16 end
- global testString1 := new Text string:"edit me, pretty please!"
- global testString2 := new Text string:"oh no, edit me!"
- global testString3 := new Text string:"please, edit me first!"
- object textBox1 (TextEdit)
- boundary:(new Rect x2:384 y2:60)
- target:testString1, stroke:blackBrush
- settings x:128, y:64, cursor:myCursor
- end
- setDefaultAttr textBox1 @alignment @center
- object textBox2 (TextEdit)
- boundary:(new Rect x2:384 y2:60)
- target:testString2, stroke:blackBrush
- settings x:128, y:128, cursor:myCursor
- end
- setDefaultAttr textBox2 @alignment @center
- object textBox3 (TextEdit)
- boundary:(new Rect x2:384 y2:60)
- target:testString3, stroke:blackBrush
- settings x:128, y:192, cursor:myCursor
- end
- setDefaultAttr textBox3 @alignment @center
- append myWindow textBox1
- append myWindow textBox2
- append myWindow textBox3
- show myWindow
-
- -- >>>
-